<template>
	<view class="content">
<!-- 		<view class="sb">
			<image class="image_11X1" src="/static/国徽.webp"></image>
		</view>
		
		<text class="text_148X1">延边朝鲜族自治州委政法委</text> -->
<!-- 		<view class="zt">
			<view class="jb">涉黑涉恶线索举报</view>
			<view class="ts">(注意:标有 * 的必须填写)</view>	
		</view> -->
		<view class="background">
		
			<view class="person">
				<text class="bt">举报人信息</text>
			</view>
			<view class="border">
				<view class="input-area">
					<view class="title">姓名
						<text class="red-star">*</text>
					</view>
					<input v-model="report.reportName" type="text" class="input-field"  placeholder="您的真实姓名"/>
					<view class="title">身份证号
						<text class="red-star">*</text>
					</view>
					<input v-model="report.reportIdentityCard" type="number" maxlength="18"  class="input-field"  placeholder="您的身份证号"/>
					<view class="title">居住地
						<text class="red-star">*</text>
					</view>
					<input v-model="report.reportAddress" type="text" class="input-field" placeholder="您的居住地"/>
					<view class="title">联系方式
						<text class="red-star">*</text>
					</view>
					<input v-model="report.reportTel" type="text" class="input-field" placeholder="您的联系方式"/>
				</view>
			</view>
			<view class="person">
				<text class="bt">被举报人(单位)信息</text>
			</view>
			<view class="border">
				<view class="input-area">
					<view class="title">被举报人
						<text class="red-star">*</text>
					</view>
					<input v-model="report.beReportedName" type="text" class="input-field"  placeholder="请输入被举报人"/>
					<view class="title">单位
						<text class="red-star">*</text>
					</view>
					<input v-model="report.beReportedUnit" type="text" class="input-field"  placeholder="请输入单位"/>
					<view class="title">职务
						<text class="red-star">*</text>
					</view>
					<input v-model="report.beReportedOffice" type="text" class="input-field" placeholder="请输入职务"/>
					<view class="title">级别
						<text class="red-star">*</text>
					</view>
					<input v-model="report.beReportedLevel" type="text" class="input-field" placeholder="请输入级别"/>
				</view>
			</view>
			<view class="person">
				<text class="bt">举报正文</text>
			</view>
			<view class="border">
				<view class="input-area">
					<view class="title">标题
						<text class="red-star">*</text>
					</view>
					<input v-model="report.title" type="text" class="input-field"  placeholder="标题"/>
					<view class="title">问题类别
						<text class="red-star">*</text>
						
					</view>
					   <view>
						   <picker style="width: 85%;" class="input-field" mode="selector" :range="items" @change="handleChange" >
								<view class="picker">{{leib.substring(0,16)+'...'}}</view>
						   </picker>
					   </view>
					<view class="title">
						<!-- 具体问题类别 -->
						<view style="width: 93%;" v-if="leib!='请选择'">{{leib}}</view>
					</view>
					<view class="title">主要问题
						<text class="red-star">*</text>
					</view>
					<textarea v-model="report.content" class="zywt"placeholder="请输入"></textarea>
					<view style="justify-content: center; align-items: center;">
						<button class="sc" @click="shfj()">上传附件</button>
						<view class="item" v-for="(item,index) in photographPics" :key="index">
							<view class="" >{{item.fileName}}</view>
							
						</view>
					</view>
				
					<view class="text1">
						<view>
							温馨提示：最多可同时上传4个文件，每个文件只允许上传5M大小。附件仅限于文件名 
						</view>
						<view >
							后缀为.jpg、.png、.gif、.jpeg、,tiff、.svg的文件，禁止exe、bat等格式文件上传！
						</view>
					</view>
			
				</view>
			</view>
			<view class="footer">
				<button class="button1" @click="nmjb()">实名举报</button>
			</view>
		</view>
	</view>
</template>

<script>
	
	import * as dictData from '@/api/dictData/index';
	import { baseUrl, baseApi } from '@/config';
	import FileApi from '@/api/infra/file.js';
	import idCardNumberVerify from "@/store/idCardNumber/index";
	import * as ReportingApi from '@/api/reporting/index';
	export default {
		onLoad(options) {
			const category = options.category; // 获取传递的参数  
			this.report.isAnonymity = options.smjb;
			this.report.category =options.smjb;
			this.leixing = category;
			// 在这里处理参数  
			this.cxlb(category)
			console.log(options)
			
			//将openid存到投诉表的userId字段
			const app = getApp();
			const openId = app.globalData.openId;
			this.report.userId=openId;
		},
		data() {
			return {
				items:[],
				leib:'请选择',
				photographPics:[],
				tempFilePaths: [],
				leixing:'',
				report:{
					id:'',
					isAnonymity:'',
					userId:'',
					reportName:'',
					reportIdentityCard:'',
					reportAddress:'',
					reportTel:'',
					beReportedName:'',
					beReportedUnit:'',
					beReportedOffice:'',
					beReportedLevel:'',
					title:'',
					category:'',
					categoryDetail:'',
					content:'',
					fileId:'',
					clueSituation:'',
					illustrate:'',
					remark:'',
					// 用于存储选择的图片路径
					imagePaths: [],
					reportingFiles:[]
					
				},
				params:{
					dictType:'',
				}
			
			}
			
		},
		methods: {
			async cxlb(category){
				this.params.dictType=category
				const res = await dictData.getDict(this.params);
				this.items = res.data.list.map(item => item.label);
			},
			 handleChange(e) {
			      const  value  = e.detail.value;
			      this.leib = this.items[value];
				  this.report.categoryDetail =value
			    },
			
			async nmjb(category){
				var idCardMsg = idCardNumberVerify.identityIDCard(this.report.reportIdentityCard);
				if (!idCardMsg.isPass) {
					uni.showToast({
						title: idCardMsg.errorMsg,
						icon: 'none'
					})
					return;
				}
				var phone = /^1[3456789]\d{9}$/;
				if (!phone.test(this.report.reportTel)) {
					uni.showToast({
						title: "手机号格式错误",
						icon: 'none'
					})
				}
				//将临时路径上传到文件服务器并返回图片地址
				// let objectList = this.photographPics.map(filePath,fileName => ({ file: filePath,fileName:fileName }));
				this.report.reportingFiles=this.photographPics
				const res = await ReportingApi.createReporting(this.report);
				const leixing = this.leixing; // 保存 leixing 到局部变量  
				if(res.code == '0'){
					uni.showToast({
						 title: '实名举报成功',//显示的文字
						 duration: 2000,  //显示多少毫秒，默认1500毫秒，时间到自动隐藏
						 icon: "success"  //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none	
					})
					setTimeout(function() {
						uni.redirectTo({
							 url: '/pages/work/ewm/index?'+'id='+res.data+'&category=smjb&leixing='+leixing
							// url: '/pages/work/xiangqing/smjb?id='+res.data+'&category='
						})  
					}, 500);				
							
				}else{
					uni.showToast({
						title: '实名举报成功'+ res.msg,//显示的文字
						duration: 2000,  //显示多少毫秒，默认1500毫秒，时间到自动隐藏
						icon: "error"  //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none			
						})
				}
			},
			async shfj(){
			      uni.chooseImage({
					count: 4,
					success: (res) => {
						const tempFilePaths = res.tempFilePaths; // 获取用户选择的文件路径数组
						console.log("2222",res.tempFilePaths)
					   tempFilePaths.forEach((filePath, index) => {
							const fileName = filePath.split('/').pop();
						   uni.uploadFile({
							 url: baseUrl + baseApi + '/infra/file/upload', // Spring Boot 后端服务的 URL
							 filePath: filePath,
							 name: 'file', // 文件对应的 key，后端会通过这个 key 来获取文件
							 header: {
							   // Accept: 'text/json',
							   Accept : '*/*',
							   'tenant-id' :'1',
							   // Authorization:  'Bearer test247',
							 },
							 success: (uploadFileRes) => {
								 const data = JSON.parse(uploadFileRes.data);
								 console.log('上传成功：', data);
							   this.photographPics.push({ file: data.data,fileName:fileName })
							 },
							 fail: (err) => {
							   console.error('上传失败：', err);
							 }
						   });
					   });
					},
					fail: (err) => {
						console.error('选择文件失败：', err);
					}
			    });
			},
		}
	}
</script>

<style>
	.jb{
		margin-top: 4%;
		text-align: center;
		font-weight: bold;
	}
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.sb {
		top: 100px;
		width: 414px;
		height: 65px;
		top: -4px;
		color: rgba(80, 80, 80, 1);
		background-color: rgba(51, 103, 153, 1);
		font-size: 18px;
		line-height: center;
		text-align: center;
		flex-direction: column;
		/* 设置为列方向布局 */
		align-items: center;
		/* 垂直居中 */
		justify-content: center;
		/* 水平居中（但在这里我们主要关心垂直居中，所以可能需要调整） */
	}
	
	.image_11X1 {
		width: 30px;
		height: 30px;
		left: -40%;
		top: 24px;
	}
	
	.text_148X1 {
		margin-top: -10%;
		width: auto;
		height: 33px;
		left: 51px;
		top: 55px;
		color: rgba(255, 255, 255, 1);
		text-shadow: rgba(0, 0, 0, 0.5) 0px 2px 2px;
		font-size: 18px;
		line-height: 150%;
		text-align: left;
		font-weight: bold;
		padding-right: 80px;
	}
	.zt{
		width: 100%;
	}
	.ts{
		margin-top: 3%;
		margin-left: 56%;
	}
	.person{
		width: 100%;
		margin-top: 4%;
		margin-left: 4%;
		font-weight: bold;
		font-size: 14px;
	}
	.bt{
		color: rgba(51, 103, 153, 1);
		font-size: 16px;
	}
	.input-field {
	  width: 90%; /* 或者你需要的宽度 */
	  border: 1px solid #ccc; /* 添加边框 */
	  padding: 1px; /* 添加内边距，使输入框看起来更舒适 */
	  border-radius: 5px;
	  margin-top: 2%;
	  height: 30px;
	  font-size:14px;
	  padding-left: 11px;
	}
	.title{
		font-size: 14px;
		color:#888685;
		margin-top: 2%;
	}
	.border{
		
		margin-top: 2%;
		border-radius: 10px;
		width: 90%;
		background-color: white;
		margin-left: 4%;
		padding: 1px 0;
	}
	.input-area{
		 width: 100%;
		 margin-left: 5%;
		 margin-top: 1%;
		 margin-bottom: 5%;
	}
	.red-star{
		color: red;
		margin-left: 1%;
	}
	.button1 {
		width:50%;
		height: 35px;
		/* padding: 10px 10px; */
		margin-top: 8%;
		margin-bottom: 13%;
		border: none;
		border-radius: 5px;
		background-color:#0082df;
		color: white;
		font-size: 16px;
		cursor: pointer;
	}
	.sc{
			margin-top: 3%;
			justify-content: center; 
			align-items: center;
			display: flex;
		    background-color: #0082df;
		    width: 80px;
		    font-size: 11px;
		    color: white;
		    margin-left: 1%;
			height: 25px;
			text-align: center;
	}
	.footer{
		width: 100%;
	}
	.text1{
		margin-top: 2%;
		width: 90%;
		color: #0082df;
		margin-bottom: 5%;
	}
	.zywt{
		width: 90%;
		border: 1px solid #ccc; /* 添加边框 */
		padding: 1px; /* 添加内边距，使输入框看起来更舒适 */
		border-radius: 5px;
		margin-top: 2%;
		font-size:14px;
		padding-left: 11px;
	}
	.picker{
		margin-top:2%;
		align-items: center;
		display: flex;
	}
	.background{
		margin: 0px 10px;
		background-color: #ebf8ff;
		border-radius: 12px;
		/* padding: 10px 0px; */
	}
</style>
